<template>
  <div id="login_id">
      <div class="borderd">
        <div class="form_panel">
          <p class="top">
            优质甄选 高枕无忧
          </p>
          <div class="form">
            <p class="input-item">
              <input type="text" placeholder="请输入您的用户名" v-model.trim = 'form_data.username'>
            </p>
            <p class="input-item">
              <input type="password" placeholder="请输入相应的密码" v-model.trim = 'form_data.password'>
            </p>
            <p class="input-item">
              <button type='button' @click='submit'>登&nbsp;&nbsp;&nbsp;录</button>
            </p>
          </div>
        </div>
      </div>
  </div>
</template>

<script>
export default {
  //获取表单数据
  //校验数据
  //存储登录状态
  //发起跳转
  data(){
    return {
      form_data:{
        username:'admin',
        password:'admin888'
      }
    }
  },
  methods:{
    submit(){
      if(this.form_data.username === ''){
        return alert('用户名不可为空')
      }
      if(this.form_data.password === ''){
        return alert('密码不可为空')
      }
      this.$http.post('/api/userlogin',this.form_data).then(res=>{
        console.log(res);
        if(res.code === 200){
          var login_data = JSON.stringify(res.list)
          //存储登录状态
          localStorage.setItem('logindata',login_data)
          //跳转
          this.$router.push('/index')
        }
      })
      // console.log(this.form_data);
    }
  }
}
</script>

<style>
#login_id{
  width: 100%;
  height: 100vh;
  background-image: linear-gradient(to bottom,#ff5d3E,#eb8b7a);
  position: relative;
}
#login_id .borderd{
  width: 700px;
  height: 553px;
  background: url('../assets/img/loginbg.png') no-repeat;
  background-size: 100%;
  position: absolute;
  right: 20vh;
  top: 10vh;
}
.form_panel{
  width: 300px;
  height: 500px;
  position: absolute;
  top: 50px;
  right: 55px;
  background-image: url('../assets/img/logo.png');
  background-repeat: no-repeat;
  background-position-y:80px;
  background-size: 300px;
}
.form_panel .top{
  letter-spacing: 5px;
  width: 100%;
  text-align: center;
  position: absolute;
  top: 180px;
  color: #AAA8A8;
}
.form_panel .form{
  width: 100%;
  position: absolute;
  top: 250px;
}
.form_panel .form .input-item input{
  width: 100%;
  height: 30px;
  margin-bottom: 20px;
  outline: none;
  border: none;
  border-bottom: 2px solid #ff5d3E;
  background-color: #FFF5F3;
  padding-left: 10px;
  box-sizing:border-box;
}
.form_panel .form .input-item button{
  width: 100%;
  height: 30px;
  border-radius: 50px;
  outline: none;
  border: none;
  color: #fff;
  background-color: #F64B35;
  box-shadow: 0px 5px 10px rgb(173, 173, 173);
  margin-top: 10px;
  cursor: pointer;
}
</style>